

<div class="layui-form" lay-filter="layuiadmin-form-works" style="padding: 20px 30px 0 0;">
    <!-- 作品ID（隐藏字段，编辑时必填） -->
    <div class="layui-form-item" style="display: none;">
        <label class="layui-form-label">工作ID</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="worksId" value="{{ d.params.worksId || '' }}"
                       autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <!-- 作品类型（回显选中状态） -->
    <div class="layui-form-item">
        <label class="layui-form-label">工作类型</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="hidden" name="typeIdH" id="typeIdH" value="{{ d.params.typeId || '' }}" />
                <select name="typeId" id="typeId">
                    <option value="" selected>请选择工作类型</option>
                </select>
            </script>
        </div>
    </div>

    <!-- 作品名称（回显原有值） -->
    <div class="layui-form-item">
        <label class="layui-form-label">工作名称</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="worksName" value="{{ d.params.worksName || '' }}" lay-verify="required"
                       placeholder="请输入作品名称" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <!-- 作品排序（回显原有排序值） -->
    <div class="layui-form-item">
        <label class="layui-form-label">工作排序</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="worksOrder" value="{{ d.params.worksOrder || 0 }}" lay-verify="required|number"
                       placeholder="请输入排序号" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <!-- 作品状态（回显原有状态） -->
    <div class="layui-form-item" lay-filter="cflag">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="radio" name="worksFlag" value="0" title="启用"
                       {{ (d.params.worksFlag === '启用' || d.params.worksFlag === '0') ? 'checked' : '' }}>
                <input type="radio" name="worksFlag" value="1" title="禁用"
                       {{ (d.params.worksFlag === '禁用' || d.params.worksFlag === '1') ? 'checked' : '' }}>
            </script>
        </div>
    </div>

    <!-- 提交按钮（修改为"确认"文案） -->
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="LAY-modify" value="确认" class="layui-btn">
        </div>
    </div>
</div>

<script>
layui.use(['admin', 'form'], function(){
  var $ = layui.$
  ,form = layui.form;
  
});
layui.use([ 'form', 'layer' ], function() {
	$ = layui.$;
	var form = layui.form, layer = layui.layer;

    $.ajax({
        url: '/getTypesServlet',
        dataType: 'json',
        type: 'post',
        timeout: 10000,
        success: function(data) {
            $.each(data.data, function(index, value) {
                $('#typeId').append(
                    new Option(value.typeName, value.typeId)
                );
            });
//1111
            // 回显编辑数据的类型（通过隐藏域的值匹配）
            var defaultTypeId = $('#typeIdH').val();
            if (defaultTypeId && defaultTypeId !== '') {
                $('#typeId').val(defaultTypeId);
            }

            form.render("select");
        },
        error: function() {
            layer.msg('作品类型加载失败', {icon: 2});
        }
    });
});
</script>